package cn.online.taxi.common.utils;

/**
 * @Author BinBini
 * @Date 2021/4/12 10:12
 * @Version 1.0
 */
public class LatNLongDistance {

    public static double distanceByLongNLat(double startLongitude, double startLatitude, double targetLongitude, double targetLatitude) {
        double differLatitude, differLongitude, R;
        R = 6378137;//地球半径
        startLatitude = startLatitude * Math.PI / 180.0;
        targetLatitude = targetLatitude * Math.PI / 180.0;
        differLatitude = startLatitude - targetLatitude;
        differLongitude = (startLongitude - targetLongitude) * Math.PI / 180.0;
        double distance;    // 距离
        double sa2, sb2;
        sa2 = Math.sin(differLatitude / 2.0);
        sb2 = Math.sin(differLongitude / 2.0);
        distance = 2 * R * Math.asin(Math.sqrt(sa2 * sa2 + Math.cos(startLatitude) * Math.cos(targetLatitude) * sb2 * sb2));
        return distance;
    }

}
